package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.TeacherDao;
import com.itheima.edu.info.manager.domain.Teacher;

public class TeacherSeivice {

    private TeacherDao teacherDao = new TeacherDao();


    public static boolean addTeacher(Teacher t) {

        return TeacherDao.addTeacher(t);
    }

    public static boolean isExists(String id) {

        Teacher[] teachers = TeacherDao.findAllTeacher();

        boolean exists = false;

        for (int i = 0; i < teachers.length; i++) {
            Teacher teacher = teachers[i];
            if(teacher != null && teacher.getId().equals(id)){
                exists = true;
                break;
            }
        }
        return exists;
    }

    public static Teacher[] findAllTeacher() {

        Teacher[] allTeacher = TeacherDao.findAllTeacher();
        boolean flag = false;
        for (int i = 0; i < allTeacher.length; i++) {
            Teacher t = allTeacher[i];
            if(t != null){
                flag = true;
                break;
            }
        }

        if(flag){
            return allTeacher;
        }else{
            return null;
        }
    }

    public static void deleteTeacherById(String id) {

        TeacherDao.deleteTeacherById(id);

    }


    public static void updateTeacher(String id, Teacher newTeacher) {
        TeacherDao.updateTeacher(id,newTeacher);
    }
}
